const questionsTypeMap = {
  '0': 'radio', // 单选
  '1': 'checkbox', // 多选
  '2': 'blank', // 填空
  // '2': 'blankForm', // 填空
  '3': 'sort', // 排序
}

const handleQuestion = function(resData) {
  const data = resData
  let questionsList = []
  questionsList = data.map(item => {
    if (item.choices && item.choices.length) {
      item.choices.forEach(c => {
        if (c.type === 1) {
          c.isBlank = true
        }
        if (c.isExclude === 1) {
          c.isExclude = true
        }
      })
    }
    const obj = {
      isShow: item.isShow, // 是否展示该题目，用于跳题逻辑
      isCanDelete: item.isAddByInterview || false,
      questionNumber: item.number, // 题目序号，用于跳题逻辑
      questionId: item.id,
      questionType: questionsTypeMap[item.type], // 题型
      questionName: item.content, // 题干
      questionDesc: null, // 题目描述
      requiredFlag: !!item.required, // 是否必填
      questionContent: item.choices,
      questionMin: item.minChoices,
      questionMax: item.maxChoices,
      componentName: questionsTypeMap[item.type],
      error: item.error || ''
    }
    return obj
  })
  // console.log('questionsList', questionsList)
  return questionsList
}

const handleQuestionnaireData = function(data) {
  const { questions, disabled, name } = data
  const obj = {
    name,
    disabled,
    questions: handleQuestion(questions)
  }
  return obj
}
export default {
  handleQuestionnaireData,
  handleQuestion
}
